package com.macro.mall.es.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.common.dto.EsIndexDto;
import com.macro.mall.common.dto.EsTableDto;
import com.macro.mall.common.dto.EsTableRes;
import com.macro.mall.es.service.EsIndexService;
import com.macro.mall.es.service.EsTableService;
import com.macro.mall.model.PmsProutr;
import com.macro.mall.model.PmsSkuStock;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * es文档服务
 */
@RestController
@RequestMapping("/table")
public class EsTableController {
    @Resource
    private EsTableService esTableService;

    /**
     * es批量添加
     * @param responseList
     * @return
     */
    @PostMapping("/doAddAll")
    public CommonResult doAddAll(@RequestBody List<PmsProutr> responseList){
        CommonResult result=esTableService.doAddAll(responseList);
        return result;
    }
    /**
     * 删除全部索引内容
     * @param indexName
     */
    @PostMapping("/delAll/{indexName}")
    public void delAll(@PathVariable String indexName){
        esTableService.delAll(indexName);
    }

    /**
     * 单个删除
     * @param esIndexDto
     */
    @PostMapping("/delEs")
    public void delEs(@RequestBody EsTableDto esIndexDto){
        esTableService.delEs(esIndexDto);
    }

    /**
     * es查询
     * @param esTableRes
     * @return
     */
    @PostMapping("/search")
    public CommonResult <Map<String,Object>> search(@Validated @RequestBody EsTableRes esTableRes){
        Map<String,Object> result=esTableService.search(esTableRes);
        return CommonResult.success(result);
    }
}
